<?php
// 本类由系统自动生成，仅供测试用途
class TeacherAction extends CommonAction {
    public function index(){
	$teacher_name = getinfo($_SESSION['teacher_id'],'teacher','XM');
	$pic =  getinfo($_SESSION['teacher_id'],'teacher','pic');
    $this->assign('teacher_name',$teacher_name);

    $this->assign('pic',$pic);

	$this->display();
    }

    public function proc_save(){
    	$id =$this ->_insert('Class_proclamation');
    	if ($id)
        {
        	add_log($_SESSION['teacher_id'],'添加 ID:'.$id.'公告',2);

             $this ->success('操作成功',__URL__.'/proc_class');
        }
    }


    public function proc_class(){
        if (!empty($_REQUEST['time']))
        {
			$aa = strtotime($_REQUEST['time']).','.(strtotime($_REQUEST['time'])+86400);
            $map['FBSJ'] = array('BETWEEN',$aa);
        }

        if (!empty($_REQUEST['title']))
        {
            $map['title'] = array('like','%'.$_REQUEST['title'].'%');
        }
        //$map['school_id'] = $_SESSION['school_id'];
        $map['class_id']  = array(' in',loadpower(1));
        // print_r($map);
        $mschool_proclamation =M('class_proclamation');
        $this->_listpage($mschool_proclamation, $map, $sortBy = '', $asc = false , 0 , $db = '',$listRows='15');
        $this->display();
    }


	public function proc_school(){
        if (!empty($_REQUEST['time']))
        {
			$aa = strtotime($_REQUEST['time']).','.(strtotime($_REQUEST['time'])+86400);
            $map['FBSJ'] = array('BETWEEN',$aa);
        }

        if (!empty($_REQUEST['title']))
        {
            $map['title'] = array('like','%'.$_REQUEST['title'].'%');
        }
        $map['school_id'] = $_SESSION['school_id'];

        $mschool_proclamation =M('school_proclamation');
        $this->_listpage($mschool_proclamation, $map, $sortBy = '', $asc = false , 0 , $db = '',$listRows='15');
        $this->display();
	}

    //手机界面
	public function mobile()
	{
		$this->display();
	}



    //课程表方法
	public function lesson_info()
	{
		$class_id= $_REQUEST['class_id'];
		$map['school_id']=$_SESSION['school_id'];
        $week = loadweek($_REQUEST['time']);
        $this ->_loadlessontype();
        $this->assign('week',$week);
        $this->assign('teacher_id',$_SESSION['teacher_id']);
        $this->assign('class_id',$class_id);

		$this->display();
	}

	public function lesson_class_info()
	{
		$class_id= $_REQUEST['class_id'];
		$map['school_id']=$_SESSION['school_id'];
		$mteacher =M('teacher');
        $teacher = $mteacher->where($map)->select();
        $week = loadweek($_REQUEST['time']);
        $this->assign('week',$week);
        $this->assign('teacher_id',$_REQUEST['teacher_id']);
        $this->assign('teacher',$teacher);
        $this->assign('class_id',$class_id);
        $this ->_loadlessontype();
		$this->display();
	}
	//课程表方法


	//成绩方法

	public function score_man()
	{

		$mstudent= M('student');
		$map['school_id']=$_SESSION['school_id'];
		$school_type =getinfo($map['school_id'],'school','school_type_id');
		$level= M('level');
		$levellist = $level->where('school_type_id = '.$school_type)->select();
		if (!empty($_REQUEST['name']))
        {
           $map['XM'] = array('like','%'.$_REQUEST['name'].'%');
        }
        $exam_id =$_REQUEST['exam_id'];

        //$mstudent_result =M('student_result');
        $this->assign('levellist',$levellist);
        $this->assign('exam_id',$exam_id);
		$this->_listpage($mstudent, $map, $sortBy = '', $asc = false , 0 , $db = '',$listRows='15');
		$this->display();
	}

	public function loadresult()
	{
		$student_id =$_REQUEST['sid'];
		if (!empty($_REQUEST['exam_id']))
        {
           $wstr = ' and exam.id ='.$_REQUEST['exam_id'];
        }
		$class_id = getinfo($student_id,'student','class_id');
		$mexam =M('exam');

		$examlist = $mexam->where('id in (select (exam_id)  from  student_result where student_id ='.$student_id.")".$wstr)->select();
		//echo $mexam->getlastsql();
		$this->assign('examlist',$examlist);
		$this->assign('student_id',$student_id);
		$this->display();
	}

	public function score_add()
	{
		$map['school_id']=$_SESSION['school_id'];
		$mstudent = M('student');
		$school_type =getinfo($map['school_id'],'school','school_type_id');
		$level= M('level');

		$msubject =M('subject');
		$subject =$msubject->where($map)->select();
		$levellist = $level->where('school_type_id = '.$school_type)->select();
		$class_id = $_REQUEST['class_id'];

		$idlist =loadpower(3);
		$mclass =M('class');
		$mapcl['id'] = array('in',$idlist);
		$classlist =$mclass->where($mapcl)->select();
		if (!empty($_REQUEST['class_id']))
        {
            $mapst['class_id'] = $_REQUEST['class_id'];
        }
		$studentlist =$mstudent->where($mapst)->select();
		$this->assign('classlist',$classlist);
		$this->assign('class_id',$class_id);
		$this->assign('levellist',$levellist);
		$this->assign('studentlist',$studentlist);
		$this ->assign('subject',$subject);
		$this->display();
	}
	public function score_import()
	{
		$map['school_id']=$_SESSION['school_id'];
		$mstudent = M('student');
		$school_type =getinfo($map['school_id'],'school','school_type_id');
		$level= M('level');

		$msubject =M('subject');
		$subject =$msubject->where($map)->select();
		$levellist = $level->where('school_type_id = '.$school_type)->select();
		$class_id = $_REQUEST['class_id'];

		$idlist =loadpower(3);
		$mclass =M('class');
		$mapcl['id'] = array('in',$idlist);
		$classlist =$mclass->where($mapcl)->select();
		if (!empty($_REQUEST['class_id']))
        {
            $mapst['class_id'] = $_REQUEST['class_id'];
        }
		$studentlist =$mstudent->where($mapst)->select();
		$this->assign('classlist',$classlist);
		$this->assign('class_id',$class_id);
		$this->assign('levellist',$levellist);
		$this->assign('studentlist',$studentlist);
		$this ->assign('subject',$subject);
		$this->display();
	}

	public function score_save()
	{
		$map['school_id']=$_SESSION['school_id'];
		$msubject =M('subject');
		$mstudent = M('student');
		$mstudent_result = M('student_result');
		$data =$this ->_post();

		if (!empty($data['class_id']))
		{
			if (empty($data['level_id']) or empty($data['term']))
			{
				$this->error('信息填写不完整');
			}
			$level = getinfo($data['level_id'],'level','level');
			$cslevel_id =getinfo($data['class_id'],'class','level_id');
			$cslevel =getinfo($cslevel_id,'level','level');
			if ($cslevel<$level)
			{
				$this->error('不能录入大于当前年级的成绩');
			}
			$add =$data['add'];
			if ($add==1)
			{
				if (empty($data['exam_name']) or empty($data['KSRQ']))
				{
					$this->error('信息填写不完整');
				}
				$dataex['exam_name'] = $data['exam_name'];
				$dataex['KSRQ'] = strtotime($data['KSRQ']);
				$dataex['level_id'] =$data['level_id'];
				$dataex['term'] =$data['term'];
				$dataex['school_id'] =$_SESSION['school_id'];
				$mexam =M('exam');
				$exam_id = $mexam ->add($dataex);
				$map['school_id']=$_SESSION['school_id'];

				if (!empty($_REQUEST['class_id']))
		        {
		            $mapst['class_id'] = $_REQUEST['class_id'];
		        }
				$studentlist =$mstudent->where($mapst)->select();

				$subject =$msubject->where($map)->select();
				foreach ($subject as $sj) {
					foreach ($studentlist as $stl) {
						if (!empty($data['subject_'.$sj['id'].'_'.$stl['id']]))
						{
							//echo $data['subject_'.$sj['id'].'_'.$stl['id']],'<br>';
							$datares['subject_id'] =$sj['id'];
							$datares['student_id'] = $stl['id'];
							$datares['FSLKSCJ'] =$data['subject_'.$sj['id'].'_'.$stl['id']];
							$datares['exam_id'] =$exam_id;
							$mstudent_result ->add($datares);

						}

					}
				}
				add_log($_SESSION['teacher_id'],'录入成绩表',2);
				$this->success('操作成功',__URL__.'/score_man');


			}
			else if ($add==2)
			{
				if (empty($data['exam_id']))
				{
					$this->error('信息填写不完整');
				}
				if (!empty($_REQUEST['class_id']))
		        {
		            $mapst['class_id'] = $_REQUEST['class_id'];
		        }
				$studentlist =$mstudent->where($mapst)->select();

				$subject =$msubject->where($map)->select();
				foreach ($subject as $sj) {
					foreach ($studentlist as $stl) {
						if (!empty($data['subject_'.$sj['id'].'_'.$stl['id']]))
						{
							$mapres['exam_id'] = $data['exam_id'];
							$mapres['student_id'] = $stl['id'];
							$mapres['subject_id'] =$sj['id'];

							$datares['subject_id'] =$sj['id'];
							$datares['student_id'] = $stl['id'];
							$datares['FSLKSCJ'] =$data['subject_'.$sj['id'].'_'.$stl['id']];
							$datares['exam_id'] =$data['exam_id'];

							if ($mstudent_result ->where($mapres)->count()>0)
							{
								$mstudent_result ->where($mapres)->save($datares);
							}
							else
							{
								$mstudent_result ->add($datares);
							}
						}


					}
				}

				add_log($_SESSION['teacher_id'],'录入成绩表',2);
				$this->success('操作成功');

			}



		}
		else
		{
			$this->error('数据不完整');
		}


	}
	public function score_onesave()
	{
		$data =$this->_post();
		if (!$data['exam_id'] or !$data['student_id'])
		{
			$this->error('参数不完整');
		}

		$mstudent_result=M('student_result');
		$mapsu['school_id']=session('school_id');
		$msubject =M('subject');


		$subject =$msubject->where($mapsu)->select();
		foreach ($subject as $sj) {
			$dasure ='';
			$dasure = $data['subject_'.$sj['id']];
			if ($mstudent_result->where('exam_id ='.$data['exam_id'].' and student_id = '.$data['student_id'].' and subject_id='.$sj['id'])->count()>0)
			{
				$data1['FSLKSCJ'] = $dasure;
				$mstudent_result->where('exam_id ='.$data['exam_id'].' and student_id = '.$data['student_id'].' and subject_id='.$sj['id'])->save($data1);
				//echo $mstudent_result->getlastsql();
			}
			else
			{
				//echo $mstudent_result->getlastsql();
				$data1['FSLKSCJ'] = $dasure;
				$data1['subject_id'] = $data['subject_id'];
				$data1['exam_id'] = $data['exam_id'];
				$data1['student_id'] = $data['student_id'];
				$mstudent_result->add($data1);
			}
			# code...
		}
		add_log($_SESSION['teacher_id'],'修改 学生ID:'.$data['student_id'].'成绩',2);

		$this->success('操作成功',__URL__.'/score_man');



	}
	public function score_edit()
	{
		$id =$_REQUEST['id'];
		$mstudent=M('student');
		$studentinfo =$mstudent->find($id);
		$exid =$_REQUEST['exid'];
		$mexam=M('exam');
		$examinfo = $mexam->find($exid);

		$mapsu['school_id']=session('school_id');
		$msubject =M('subject');
		$subject =$msubject->where($mapsu)->select();


		$this->assign('studentinfo',$studentinfo);
		$this->assign('examinfo',$examinfo);
		$this->assign('subject',$subject);

		$this->display();
	}

	public function scoretemplate(){
		$class_id = $_GET['class_id'];

		  header("Content-type:application/octet-stream");
	      header("Accept-Ranges:bytes");
	      header("Content-type:application/vnd.ms-excel");
	      header("Content-Disposition:attachment;filename=scoretemplate_".date("Y-m-d").".xls");
	      header("Pragma: no-cache");
	      header("Expires: 0");

	echo '<html xmlns:o="urn:schemas-microsoft-com:office:office"
	    xmlns:x="urn:schemas-microsoft-com:office:excel"
	    xmlns="http://www.w3.org/TR/REC-html40">
	 <head>
	    <meta http-equiv="expires" content="Mon, 06 Jan 1999 00:00:01 GMT">
	    <meta http-equiv=Content-Type content="text/html; charset=gb2312">
	    <!--[if gte mso 9]><xml>
	    <x:ExcelWorkbook>
	    <x:ExcelWorksheets>
	      <x:ExcelWorksheet>
	      <x:Name></x:Name>
	      <x:WorksheetOptions>
	        <x:DisplayGridlines/>
	      </x:WorksheetOptions>
	      </x:ExcelWorksheet>
	    </x:ExcelWorksheets>
	    </x:ExcelWorkbook>
	    </xml><![endif]-->
	</head>';


echo "<table>" .
		"<tr>" .
			"<th>".iconv("UTF-8", "GB2312//IGNORE","学号")."</th>".
			"<th>".iconv("UTF-8", "GB2312//IGNORE","姓名")."</th>".
			$subject = M('subject');
			$map['school_id'] = $_SESSION['school_id'];
			$sublist = $subject->where($map)->order('id asc')->select();
			foreach($sublist as $k=>$l){
				echo "<th>".iconv("UTF-8", "GB2312//IGNORE",$l['KCMC'])."</th>";
			}
		echo "</tr>";


		$stu = M('student');
		$map0['class_id'] = $class_id;
		$stulist = $stu->where($map0)->order('XH asc')->select();
		foreach($stulist as $key=>$v){
			echo "<tr>";
			echo "<td style='vnd.ms-excel.numberformat:@'>".iconv("UTF-8", "GB2312//IGNORE", $v["XH"])."</td>";
			echo "<td style='vnd.ms-excel.numberformat:@'>".iconv("UTF-8", "GB2312//IGNORE", $v["XM"])."</td>";

			foreach($sublist as $k=>$l){
				echo "<td style='vnd.ms-excel.numberformat:@'>".iconv("UTF-8", "GB2312//IGNORE", "")."</td>";
			}

			echo "</tr>";
		}
		echo "</table>";
	}

	public function score_doimport(){
		$class_id = $this->_isempty($_POST['class_id'],'请选择班级ID');
		$add = $this->_isempty($_POST['add'],'请选择类型');
		$levelid = $this->_isempty($_POST['level_id'],'请选择年级');
		$term = $this->_isempty($_POST['term'],'请选择学期');


		$dir = dirname(_FILE_);//获得编译文件当前目录
		$dir = str_replace("\\", "/", $dir)."/";
		$time = time();
		$filename = 'remark'.$time.'.xls';
		$path = $dir.$filename;
		$path = "./excel/".$filename;
		$result = move_uploaded_file($_FILES['uploadfile']['tmp_name'], $path);
		if ($result){
			Vendor('excel_reader2');//调用第三方类，可以是require_once('指向reader.php文件所在的路径')
			$data = new Spreadsheet_Excel_Reader();
			$data->setOutputEncoding('utf-8');

			error_reporting(E_ALL ^ E_NOTICE);
			$data->read($path);

			$subject = M('subject');
			$map0['school_id'] = $_SESSION['school_id'];
			$sublist = $subject->where($map0)->order('id asc')->select();

			$exam_id=0;
			if ($add==1){
				if (empty( $_POST['examname']) or empty($_POST['examtime']))
				{
					$this->error('信息填写不完整');
				}
				$dataex['exam_name'] = $_POST['examname'];
				$dataex['KSRQ'] = strtotime($_POST['examtime']);
				$dataex['level_id'] =$levelid;
				$dataex['term'] =$term;
				$dataex['school_id'] = $_SESSION['school_id'];
				$mexam =M('exam');
				$exam_id = $mexam ->add($dataex);
			}else if ($add==2){
				if (empty( $_POST['exam_id']))
				{
					$this->error('信息填写不完整');
				}else{
					$exam_id = $_POST['exam_id'];
				}
			}

			$m = M('student_remark');
			$stu = M('student');
			$stures = M('student_result');

			for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
			    $arr = array();
			    for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
			        $arr[] = $data->sheets[0]['cells'][$i][$j];
			    }
			    mysql_query("set names 'utf-8'");

				if($arr[0] !="" || $arr[0] != null){
					$map['XH'] = $arr[0];
				}
				if($arr[1] !="" || $arr[1] != null){
					$map['XM'] = $arr[1];
				}

				$liststu = $stu->where($map)->find();
				if($liststu == null){
//					$this->assign('jumpUrl',__URL__.'/score_import/');
//					$this->assign('waitSecond','1');
					$this->error("第".$i."行  姓名：".$map['XH']."；学号：".$map['XM']." 数据为空");
				}else{
					foreach($sublist as $k=>$l){
						if($arr[$k+2] != "" || $arr[$k+2] != null){
							$map1['subject_id'] = $l['id'];
							$map1['exam_id'] = $exam_id;
							$map1['student_id'] = $liststu['id'];
							$isdata = $stures->where($map1)->count();
							if($isdata == 0){
								$map2['subject_id'] = $l['id'];
								$map2['FSLKSCJ'] = $arr[$k+2];
								$map2['exam_id'] =$exam_id;
								$map2['CJLRSJ'] =time();
								$map2['student_id'] = $liststu['id'];
								$stures->add($map2);
							}else{
								$this->error("第".$i."行  姓名：".$map['XH']."；学号：".$map['XM']." 已经添加成绩");
							}
						}
					}
				}
			}
//			echo "<a href='".__URL__."/score_import'>返回</a>";
//			$this->assign('waitSecond','1');
			add_log($_SESSION['teacher_id'],'导入成绩',2);

			$this->success('导入成功');
		}else{
		    $this->error("上传失败！");
		}
	}











	public function loadexam()
        {
            $map['level_id'] = $_REQUEST['lv_id'];
            $map['term'] = $_REQUEST['term'];
            $m=M('exam');
            $list = $m ->where($map)->select();
            echo json_encode($list);
        }

	//成绩方法

    //考勤方法


    public function roll_all_save()
    {
    	$data=$this->_post();
    	$mstudent=M('student');
    	$mapst['class_id']=$data['class_id'];
    	$studentlist=$mstudent->where($mapst)->select();
    	// echo $mstudent->getlastsql();

    	$mapat['class_id']=$data['class_id'];
    	$mapat['lesson_id']=$data['lesson_id'];
    	$mstudent_attence =M('student_attence');
    	$mstudent_attence->where($mapat)->delete();
    	foreach ($studentlist as $stl) {
    		# code...
    		// echo $data['at_'.$stl['id']],'<br>';
    		//echo $data['at_'.$slt['id']];
    		// if ($data['at_'.$stl['id']] == 1)
    		// {
    			$dataat['FBSJ'] = $data['time'];
    			$dataat['student_id'] = $stl['id'];
    			$dataat['lesson_id'] = $data['lesson_id'];

    			$subject_id = getinfo($data['lesson_id'],'lesson','subject_id');
    			$subject_name = getinfo($subject_id,'subject','KCMC');
    			$dataat['subject_name'] = $subject_name;

    			$lesson_type_id = getinfo($data['lesson_id'],'lesson','lesson_type_id');
    			$lessontype = getinfo($lesson_type_id,'lesson_type','type_name');
    			$dataat['type_name'] = $lessontype;



    			$dataat['class_id'] = $data['class_id'];
				$dataat['status'] = $data['at_'.$stl['id']];

				$id = $mstudent_attence->add($dataat);
				add_log($_SESSION['teacher_id'],'添加 ID:'.$id.'考勤',2);
				// echo $mstudent_attence->getlastsql();
    		// }
    	}

    	$this->success('操作成功');
    	// print_r($data);
    }

    public function roll_call()
    {

    	$school_id=$_SESSION['school_id'];
    	$map['school_id']=$school_id;
    	$mlesson_type =M('lesson_type');
        $lessonlist =$mlesson_type->where($map)->order('num asc')->select();
        $this ->assign('lessonlist',$lessonlist);

        $idlist =loadpower(3);
		$mclass =M('class');
		$mapcl['id'] = array('in',$idlist);
		$classlist =$mclass->where($mapcl)->select();

		if (!empty($_REQUEST['class_id']))
		{


			$mlesson=M('lesson');
			$week= loadweek($_REQUEST['time']);
			$maples['lesson_type_id'] = $_REQUEST['lesson_type_id'];
			$maples['week_day'] = $week;
			$maples['class_id'] = $_REQUEST['class_id'];
			$maples['XXZT'] = 1;

			$lessoninfo = $mlesson->field('lesson.*')->join('schedule on schedule.id =lesson.schedule_id')->where($maples)->find();

			if (empty($lessoninfo))
			{
				$this->error('课程为空',__URL__.'/roll_call');
			}
			$this->assign('lessoninfo',$lessoninfo);

			$mapst['class_id'] = $_REQUEST['class_id'];
			$mstudent =M('student');
			$studentlist =$mstudent ->where($mapst)->select();

			$this->assign('studentlist',$studentlist);
			$timeint = strtotime($_REQUEST['time']);
			$timestr =date('Y-m-d',$timeint);
			$time = strtotime($timestr);
			$this->assign('class_id',$class_id);
			$this->assign('time',$time);
			$this->assign('timestr',$timestr);

			$map['FBSJ'] = $timeint;
			$map['class_id']=$_REQUEST['class_id'];
			$map['lesson_id']=$lessoninfo['id'];
			$mstudent_attence = M('student_attence');
			$count = $mstudent_attence->where($map)->count();
			$this->assign('count',$count);
			if ($count>0)
			{
				$this->error('对不起，该班级课次已有考勤记录,请到考勤管理查询。');
			}
		}

		$this->assign('class_id',$_REQUEST['class_id']);
		//获取lesson
		$this->assign('classlist',$classlist);
    	$this->display();
    }
    public function attence()
    {
    	$mstudent_attence =M('student_attence');

    	$class_id =getinfo($_REQUEST['student_id'],'student','class_id');
    	$data['FBSJ'] = $_REQUEST['time'];
    	$data['student_id'] = $_REQUEST['student_id'];
    	$data['lesson_id'] = $_REQUEST['lesson_id'];
    	$data['class_id'] = $class_id;
		$lesson_type_id =getinfo($_REQUEST['lesson_id'],'lesson','lesson_type_id');

    	$attenceinfo = $mstudent_attence->where($data)->find();
    	if (!empty($attenceinfo))
    	{
    		$this->error('考勤记录已存在');
    	}
    	if ($mstudent_attence->add($data))
    	{
    		$this->redirect('/Teacher/roll_call/lesson_type_id/'.$lesson_type_id.'/class_id/'.$class_id.'/time/'.date('Y-m-d',$_REQUEST['time']));
    	}

    }
    public function delattence()
    {
    	$mstudent_attence =M('student_attence');

    	$class_id =getinfo($_REQUEST['student_id'],'student','class_id');
    	$data['FBSJ'] = $_REQUEST['time'];
    	$data['student_id'] = $_REQUEST['student_id'];
    	$data['lesson_id'] = $_REQUEST['lesson_id'];
    	$data['class_id'] = $class_id;
		$lesson_type_id =getinfo($_REQUEST['lesson_id'],'lesson','lesson_type_id');

    	$attenceinfo = $mstudent_attence->where($data)->find();
    	if (!empty($attenceinfo))
    	{
    		$mstudent_attence->where($data)->delete();
    		$this->redirect('/Teacher/roll_call/lesson_type_id/'.$lesson_type_id.'/class_id/'.$class_id.'/time/'.date('Y-m-d',$_REQUEST['time']));
    	}
    }

    public function roll_man()
    {
    	if (!empty($_REQUEST['class_id']))
		{
			$wstr .= ' and student_attence.class_id='.$_REQUEST['class_id'];
		}
		if (!empty($_REQUEST['subject_id']))
		{
			$wstr .= " and student_attence.subject_name='".$_REQUEST['subject_id']."'";
		}

		if (!empty($_REQUEST['time']))
		{
			$wstr .= ' and student_attence.FBSJ='.strtotime($_REQUEST['time']);
		}
		if (!empty($_REQUEST['name']))
		{
			$wstr .= " and XM like '%".$_REQUEST['name']."%'";
		}
		$idlist =loadpower(3);
		//$map['student_attence.calss_id'] = array('in',$idlist);
		$map = "student_attence.calss_id in (".$idlist.")";

		$mstudent_attence =M('student_attence');

		$mapsu['school_id']=$_SESSION['school_id'];
		$msubject =M('subject');
		$subject =$msubject->where($mapsu)->select();



		import('ORG.Util.Page');// 导入分页类
		$count      = $mstudent_attence->field('student_attence.*,lesson_type_id,subject_id')->join('lesson on lesson.id =student_attence.lesson_id')->join('student on student.id = student_attence.student_id')->where($map)->where('1=1 '.$wstr)->count();// 查询满足要求的总记录数
		$Page       = new Page($count,15);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输


		$attencelist =$mstudent_attence->field('student_attence.*,lesson_type_id,subject_id')->join('lesson on lesson.id =student_attence.lesson_id')->join('student on student.id = student_attence.student_id')->where($map)->where('1=1 '.$wstr)->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign('attencelist',$attencelist);
		$this->assign('page',$show);// 赋值分页输出
		$Page->parameter   .=   "$class_id=".urlencode($_REQUEST['class_id']).'&';
		$Page->parameter   .=   "$subject_id=".urlencode($_REQUEST['subject_id']).'&';
		$Page->parameter   .=   "$time=".urlencode($_REQUEST['time']).'&';
		$Page->parameter   .=   "$name=".urlencode($_REQUEST['name']).'&';

		$this->assign('subject',$subject);
		$this->display();

    }
    public function roll_add()
    {
    	$mlesson_type =M('lesson_type');
        $lessonlist =$mlesson_type->where($map)->order('num asc')->select();
        $this ->assign('lessonlist',$lessonlist);

        $this->display();
    }

    public function roll_save()
    {
    	$data =$this->_post();

    	$mstudent =M('student');
    	$studentinfo =$mstudent->where('class_id ='.$data['class_id']." and XM='".$data['name']."' and XH ='".$data['XH']."'")->find();
    	if (empty($studentinfo))
    	{
    		$this->error('学生不存在');
    	}

    	$mlesson=M('lesson');
		$week= loadweek($data['time']);
		$maples['lesson_type_id'] = $data['lesson_type_id'];
		$maples['week_day'] = $week;
		$maples['class_id'] = $data['class_id'];
		$maples['XXZT'] = 1;

		$lessoninfo = $mlesson->field('lesson.*')->join('schedule on schedule.id =lesson.schedule_id')->where($maples)->find();
		if (empty($lessoninfo))
		{
			$this->error('课程为空');
		}
		$lesson_id = $lessoninfo['id'];
		$dataat['FBSJ'] = strtotime($data['time']);
		$dataat['student_id'] = $studentinfo['id'];
    	$dataat['lesson_id'] = $lesson_id;
    	$dataat['class_id'] = $data['class_id'];
    	$dataat['status'] = $data['status'];

    	$subject_id = getinfo($lesson_id,'lesson','subject_id');
    	$subject_name = getinfo($subject_id,'subject','KCMC');
    	$dataat['subject_name'] = $subject_name;

    	$lesson_type_id = getinfo($lesson_id,'lesson','lesson_type_id');
    	$lessontype = getinfo($lesson_type_id,'lesson_type','type_name');
    	$dataat['type_name'] = $lessontype;


    	$mstudent_attence =M('student_attence');
    	$attenceinfo = $mstudent_attence->where($dataat)->find();
    	if (!empty($attenceinfo))
    	{
    		$this->error('考勤记录已存在');
    	}
    	$aid=$mstudent_attence->add($dataat);
    	if ($aid)
    	{
    		add_log($_SESSION['teacher_id'],'添加 ID:'.$aid.'考勤',2);

    		$this->success('操作成功',__URL__.'/roll_man');
    	}


    }
    //考勤方法



	//学校，班级信息
	function shcool_class_info(){
		$school_id = $_SESSION['school_id'];
		$school = M('school');
		$school_info = $school->find($school_id);
		$this->assign('info',$school_info);


		$teacher_id = $_SESSION['teacher_id'];
//		$data['teacher_id'] = $_SESSION['teacher_id'];
		$data['school_id'] = $_SESSION['school_id'];
		if($_POST['key'] != null){
			$data['class_name'] = array('like','%'.$_POST['key'].'%');
		}
		$teacher = M('class');
		$this->_listpage($teacher,$data);
		$this->display();
	}

	//班级信息
	function class_info(){
		$id = $this->_isempty($_GET['id'],'ID不能为空');
		$m = M('class');
		$list = $m->find($id);
		$this->assign('info',$list);
		$this->display();
	}

	//学校信息
	function school_info(){
		$id = $this->_isempty($_GET['id'],'ID不能为空');
		$m = M('school');
		$info = $list = $m->find($id);
		$this->assign('info',$info);
		$this->display();
	}

	public function score_del()
	{
		$map['student_id'] =$_REQUEST['id'];
		$map['exam_id'] =$_REQUEST['exid'];
		$mstudent_result=M('student_result');
		if ($mstudent_result->where($map)->delete())
		{
			$this->success('操作成功');
		}
	}


	//作业，点评
	function remark_add(){
		$class = $this->getclassbyschool();
		$this->assign('class',$class);
		$this->display();
	}

	function doadd_remark(){
		$classid = $this->_isempty($_POST['class_id'],'请选择班级');
		$teacherid = $this->_isempty($_SESSION['teacher_id'],'非法操作');

//		$studentname = $this->_isempty($_POST['stu_id'],'请填写学生名称');
		$stuid = $_POST['stu_id'];
		if(count($stuid) == 0){
			$this->error('请选择学生');
		}
		$stu = M('student_remark');
		foreach($stuid as $k=>$l){
			$map['student_id'] = $l;
			$map['teacher_id'] = $_SESSION['teacher_id'];
			$map['school_id'] = $_SESSION['school_id'];
			$map['class_id'] = $classid;
			$map['JXPY'] = $_POST['JXPY'];
			$map['FBSJ'] = time();
			$map['teacher_or_parent'] = 1;

			$data['student_id'] = $l;
			$data['teacher_id'] = $_SESSION['teacher_id'];
			$data['school_id'] = $_SESSION['school_id'];
			$data['class_id'] = $classid;
			$isnum = $stu->where($data)->count();
			if($isnum == 0){
				$stu->add($map);
			}
		}
		$this->success("添加成功",__URL__.'/remark_man');
	}


	function remark_man(){
		$m = M('student_remark');
		$teacher_id = $_SESSION['teacher_id'];
		$data['school_id'] = $_SESSION['school_id'];
		if($_POST['class_id'] != null && $_POST['class_id'] != ""){
			$data['class_id'] = $_POST['class_id'];
		}

		if($_POST['teacher_id'] != null && $_POST['teacher_id'] != ""){
			$data['teacher_id'] = $_POST['teacher_id'];
		}

		if($_POST['student_name'] != null && $_POST['student_name'] != ""){
			$student = M('student');
			$stulist = $student->where('XM="'.$_POST[student_name].'"')->find();
			$data['student_id'] = $stulist['id'];


		}

		if($_POST['keyword'] != null && $_POST['keyword'] != ""){
			$data['JXPY'] = array('like','%'.$_POST['keyword'].'%');
		}

		$idlist =loadpower(3);
		
		$data['class_id'] = array('in',$idlist);
		//$data = "student_remark.calss_id in (".$idlist.")";

		$this->_listpage($m,$data);	

		$classlist = $this->getallclass();
		$teacherlist = $this->getallteacher();
		$this->assign('classlist',$classlist);
		$this->assign('teacherlist',$teacherlist);
		$this->display();
	}

	function remark_edit(){
		$id = $this->_isempty($_GET['id'],'ID不能为空');
		$m = M('student_remark');
		$info = $m->find($id);
		$this->assign('info',$info);
		$this->display();
	}

	function doedit_remark(){
		$id = $this->_isempty($_POST['id'],'ID不能为空');
		$m = M('student_remark');
		$data['id'] = $id;
		$data['JXPY'] = $_POST['JXPY'];
		$data['FBSJ'] = time();
		if($m->save($data)){
			$this->assign('jumpUrl',__APP__.'/Teacher/remark_man/');
			$this->assign('waitSecond','1');
			$this->success("修改成功");
		}
	}

	function delete_remark(){
		$id = $this->_isempty($_GET['id'],'ID不能为空');
		$m = M('student_remark');
		if($m->delete($id)){
			add_log($_SESSION['teacher_id'],'删除 ID:'.$id.'点评',2);
			$this->assign('jumpUrl',__APP__.'/Teacher/remark_man/');
			$this->assign('waitSecond','1');
			$this->success("删除成功");
		}
	}


	function deleteall_remark(){
		$ids = $this->_isempty($_POST['ids'],'ID不能为空');
		$m = M('student_remark');
		$data['id'] = array('in',$ids);
		if($m->where($data)->delete()){
			add_log($_SESSION['teacher_id'],'删除 ID:'.$ids.'点评',2);
			$this->assign('jumpUrl',__APP__.'/Teacher/remark_man/');
			$this->assign('waitSecond','1');
			$this->success("删除成功");
		}
	}


	function remark_import(){
		$class = $this->loadpowerclass(3);
		$this->assign('class',$class);
		$this->display();
	}


	function remark_doimport(){
		$classid = $this->_isempty($_POST['class_id'],'请选择班级');
		$dir = dirname(_FILE_);//获得编译文件当前目录
		$dir = str_replace("\\", "/", $dir)."/";
		$time = time();
		$filename = 'remark'.$time.'.xls';
		$path = $dir.$filename;
		$path = "./excel/".$filename;
		$result = move_uploaded_file($_FILES['uploadfile']['tmp_name'], $path);
		if ($result){
			Vendor('excel_reader2');//调用第三方类，可以是require_once('指向reader.php文件所在的路径')
			$data = new Spreadsheet_Excel_Reader();
			$data->setOutputEncoding('utf-8');

			error_reporting(E_ALL ^ E_NOTICE);
			$data->read($path);
			$m = M('student_remark');
			for ($i = 3; $i <= $data->sheets[0]['numRows']; $i++) {
			    $arr = array();
			    for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
			        $arr[] = $data->sheets[0]['cells'][$i][$j];
			    }
			    mysql_query("set names 'utf-8'");

				if($arr[0] !="" || $arr[0] != null){
					$student = M('student');
					$dd['XM']= $arr[0];
					$dd['class_id'] = $classid;
					$stulist = $student->where($dd)->find();
					if($stulist == null){
						$this->error("第".$i."行 ".$arr[0]."不在此班<br>");
					}else{
						$map['student_id'] = $stulist['id'];
					}
				}
				if($arr[1] !="" || $arr[1] != null){
					$map['JXPY'] = $arr[1];
				}

				if($map['student_id'] != null){
					$map0['class_id'] = $classid;
					$map0['student_id'] = $map['student_id'];
					$remark = $m->where($map0)->find();
					if($remark != null){
						$set['id'] = $remark['id'];
						$set['JXPY'] = $arr[1];
						$m->save($set);

						$this->error("第".$i."行 ".$arr[0]."已修改");

					}else{
						$map['teacher_id'] = $_SESSION['teacher_id'];
						$map['school_id'] =$_SESSION['school_id'];
						$map['class_id'] =$classid;
						$map['FBSJ'] =time();
						$map['teacher_or_parent'] = 1;
						$m->add($map);

						$this->error("第".$i."行 ".$arr[0]."已添加");
					}
					unset($map);
				}
			}

			$this->success('导入成功');
		}else{
		    $this->error("上传失败！");
		}
	}





























	function work_man(){
		$school_id = $_SESSION['school_id'];
		$teacher_id = $_SESSION['teacher_id'];

		$classlist = $this->loadpowerclass(2);

		$m = M('student_work');
		$map['teacher_id'] = $teacher_id;
		if($_POST['class_id'] != null && $_POST['class_id'] != ""){
			$map['class_id'] = $_POST['class_id'];
		}
		if($_POST['content'] != null && $_POST['content'] != ""){
			$map['content'] = array('like','%'.$_POST[content].'%');
		}
		if($_POST['FBSJ'] != null && $_POST['FBSJ'] !=""){
			$aa = strtotime($_REQUEST['FBSJ']).','.(strtotime($_REQUEST['FBSJ'])+86400);
            $map['FBSJ'] = array('BETWEEN',$aa);
			//$map['FBSJ'] = strtotime($_POST['FBSJ']);
		}
		$this->_listpage($m,$map);


		$this->assign('classlist',$classlist);
		$this->display();
	}

	function work_add(){
		$classlist = $this->loadpowerclass(2);
		$teacher_id = $_SESSION['teacher_id'];
		$m = M('teacher');
		$tealist = $m->find($teacher_id);

		$subjectlist = $this->getselfsubject($tealist['subject_id']);
		$this->assign('time',date('Y-m-d H:i:s'));
		$this->assign('teacher_id',$_SESSION['teacher_id']);
		$this->assign('subjectlist',$subjectlist);
		$this->assign('classlist',$classlist);
		$this->display();
	}



	function work_doadd(){
		$school_id = $_SESSION['school_id'];
		$teacher_id = $_SESSION['teacher_id'];
		$data['teacher_id'] = $teacher_id;
		$data['school_id'] = $school_id;
		$data['title'] = $_POST['title'];
		$data['class_id'] = $_POST['class_id'];
		$data['content'] = $_POST['content'];
		$data['FBSJ'] = strtotime($_POST['FBSJ']);
		$data['work_time'] = strtotime($_POST['work_time']);
		$data['subject_id'] = $_POST['subject_id'];
		$m = M('student_work');
		if($m->add($data)){
			$this->assign('jumpUrl',__APP__.'/Teacher/work_man/');
			$this->assign('waitSecond','1');
			$this->success("添加成功");
		}
	}


	function work_edit(){
		$id = $this->_isempty($_GET['id'],'ID不能为空');
		$m = M('student_work');
		$list = $m->find($id);
		$this->assign('info',$list);
		$this->display();
	}

	function work_doedit(){
		$id = $this->_isempty($_POST['id'],'ID不能为空');
		$m = M('student_work');
		$data['id'] = $id;
		$data['title'] = $_POST['title'];
		$data['content'] = $_POST['content'];
		$data['FBSJ'] = strtotime($_POST['FBSJ']);
		$data['work_time'] = strtotime($_POST['work_time']);
		if($m->save($data)){
			$this->assign('jumpUrl',__APP__.'/Teacher/work_man/');
			$this->assign('waitSecond','1');
			$this->success("修改成功");
		}
	}

	function work_delete(){
		$id = $this->_isempty($_GET['id'],'ID不能为空');
		$m = M('student_work');
		if($m->delete($id)){
			$this->assign('jumpUrl',__APP__.'/Teacher/work_man/');
			$this->assign('waitSecond','1');
			$this->success("删除成功");
		}
	}


	function work_alldelete(){
		$ids = $this->_isempty($_POST['ids'],'ID不能为空');
		$m = M('student_work');
		$data['id'] = array('in',$ids);
		$isok = $m->where($data)->delete();
		if($isok){
			$this->assign('jumpUrl',__APP__.'/Teacher/work_man/');
			$this->assign('waitSecond','1');
			$this->success("删除成功");
		}
	}


	function user_info(){
		$teacher_id = $_SESSION['teacher_id'];
		$school_id = $_SESSION['school_id'];

		$teacher = M('teacher');
		$tlist = $teacher->find($teacher_id);
		$this->assign('tlist',$tlist);


		$user = M('user');
		$ulist =  $user->find($tlist['user_id']);
		$this->assign('ulist',$ulist);

		$class1 = loadpower(2);
		$classid = explode(',',$class1);
		$map1['id'] = array('in',$classid);
		$class = M('class');
		$class1list = $class->where($map1)->select();
		$str1="";
		foreach($class1list as $k=>$l){
			$str1.=$l['class_name'].',&nbsp;&nbsp;';
		}
		$this->assign('c1list',$str1);


		$class2 = loadpower(1);
		$classid = explode(',',$class2);
		$map2['id'] = array('in',$class2);

		$class2list = $class->where($map2)->select();
		$str2="";
		foreach($class2list as $k=>$l){
			$str2.=$l['class_name'].',&nbsp;&nbsp;';
		}
		$this->assign('c2list',$str2);


		$school = M('school');
		$slist = $school->find($school_id);
		$this->assign('slist',$slist);


		$this->display();
	}


	function user_doinfo(){
		$school_id = $this->_isempty($_SESSION['school_id'],'学校ID不能为空');
		$teacher_id = $this->_isempty($_SESSION['teacher_id'],'教师ID不能为空');
		$user_id = $this->_isempty($_POST['userid'],'用户ID不能为空');

		$user = M('user');
		$teacher = M('teacher');
		$school = M('school');

		if($_POST['password'] != null && $_POST['password']!= ""){
			$userlist = $user->find($user_id);
			if($_POST['password'] != decrypt($userlist['password_des'])){
				$this->error('原密码错误');
				exit;
			}
		}

		if($_POST['newpassword1'] != null && $_POST['newpassword1'] != "" && $_POST['newpassword2'] != null && $_POST['newpassword2'] != ""){
			if($_POST['newpassword1'] == $_POST['newpassword2']){
				$data['id'] = $user_id;
				$data['password'] = $_POST['newpassword1'];
				$data['password_des'] = encrypt($_POST['newpassword1']);
				$user->save($data);
			}else{
				$this->error('两个新密码不相同');
			}
		}


		$map1['id'] = $_SESSION['teacher_id'];
		$map1['LXDH'] = $_POST['LXDH'];
		$map1['LXDZ'] = $_POST['LXDZ'];
		$map1['DZXX'] = $_POST['DZXX'];
		$map1['teacher_no'] = $_POST['teacher_no'];
		$map1['QQ'] = $_POST['QQ'];
		$map1['intro'] = $_POST['intro'];
		if($_FILES['pic']['name'] != null){
			$upload = $this->uploadimg('teacher/');
			$pic = substr($upload[0]['savepath'].$upload[0]['savename'],2);
			$map1['pic'] = $pic;
		}
		$teacher->save($map1);


		$map2['id'] = $_POST['userid'];
		$map2['SJHM'] = $_POST['SJHM'];
		$user->save($map2);

		$this->assign('jumpUrl',__APP__.'/Teacher/user_info/');
		$this->assign('waitSecond','1');
		$this->success("修改成功");

	}



	//学校，班级信息
	function school_class_info(){
		$school_id = $_SESSION['school_id'];
		$school = M('school');
		$school_info = $school->find($school_id);
		$this->assign('info',$school_info);


		$teacher_id = $_SESSION['teacher_id'];
//		$data['teacher_id'] = $_SESSION['teacher_id'];
		$classid =  loadpower(3);
		$data['id'] = array('in',$classid);
		$data['school_id'] = $_SESSION['school_id'];
		if($_POST['key'] != null){
			$data['class_name'] = array('like','%'.$_POST['key'].'%');
		}
		$teacher = M('class');
		$this->_listpage($teacher,$data);
		$this->display();
	}




	private function loadpowerclass($type){
		$id = loadpower($type);
		$arrid =explode(',',$id);
		$m = M('class');
		$data['id'] = array('in',$arrid);
		$list = $m->where($data)->select();
//		echo $m->getlastsql();
		return $list;
	}

	private function getallsubject(){
		$school_id = $_SESSION['school_id'];
		$m = M('subject');
		$data['school_id'] = $school_id;
		$list = $m->where($data)->select();
		return $list;
	}


	private function getallclass(){
		$school_id = $_SESSION['school_id'];
		$m = M('class');
		$data['school_id'] = $school_id;
		$list = $m->where($data)->select();
		return $list;
	}

	private function getallteacher(){
		$school_id = $_SESSION['school_id'];
		$m = M('teacher');
		$data['school_id'] = $school_id;
		$list = $m->where($data)->select();
		return $list;
	}


	private function getselfsubject($ids){
		$school_id = $_SESSION['school_id'];
		$arrid = explode(',',$ids);
		$m = M('subject');
		$data['school_id'] = $school_id;
		$data['id'] = array('in',$arrid);
		$list = $m->where($data)->select();
		return $list;
	}

	public function im_list()
	{
		$idlist =loadpower(3);
		$map['id'] = array('in',$idlist);
		$class=M('class');
		$classlist =$class->where($map)->select();
		$mapsc['school_id']=$_SESSION['school_id'];
		$teacher=M('teacher');
		$teacherlist =$teacher->where($mapsc)->where('id!='.$_SESSION['teacher_id'])->select();
		$this->assign('classlist',$classlist);
		$this->assign('teacherlist',$teacherlist);

		$this->display();



	}

	public function im_parent_list()
	{
		$map['class_id']=$_REQUEST['cid'];
		// $mstudent=M('student');
		// $studentlist =$mstudent->where($map)->select();
		// $this->assign('studentlist',$studentlist);
		// $this->assign('cid',$map['class_id']);
		$mparent =M('parent');
		$map_parent['student.class_id']=$map['class_id'];
		$parentlist = $mparent->field('parent.*,student.XM as studentname,student.class_id as class_id,student.id as student_id')->join('parent_power on parent.id = parent_power.parent_id')->join('student on student.id = parent_power.student_id')->where($map_parent)->select();
		$this->assign('parentlist',$parentlist);
		$this->assign('cid',$map['class_id']);


		$this->display();

	}


	public function im_save()
    {
    	$data=$this->_post();
    	$data["time"] = time();
    	$data["child_id"] = '-1';
    	$data["type"] = 'text';
		$data["state"] = 0;
    	$message = M("message");

    	$systype = getinfo($data['receive_id'],'user','systype');
    	$token = getinfo($data['receive_id'],'user','token');
    	$phone = getinfo($data['receive_id'],'user','SJHM');


    	if ($systype=='android'){
					require_once './SAM/php_sam.php';
					$conn = new SAMConnection();
					$conn->connect(SAM_MQTT, array(SAM_HOST => 'www.appbaba.com', SAM_PORT => 1883));
			 		$androidcon = '{"type":"'.$data["type"].'","child_id":"'.$child_id.'","send_id":"'.$data['send_id'].'","receive_id":"'.$data['receive_id'].'","time":"'.$data["time"].'","content":"'.$data['content'].'"}';
					$msgCpu = new SAMMessage($androidcon);
					$conn->send('topic://999/'.$token, $msgCpu);
					$conn->disconnect();

		}
		elseif($systype=='ios'){
					$body['aps'] = array( 'alert' => $data['content'],  'sound' => 'default' );
					$body['action'] = array( 'type' => $data['type'],'child_id' => $child_id,  'send_id' => $data['send_id'],  'receive_id' => $data['receive_id'], 'content' => $data['content'], 'time' =>$data["time"]  );
					$ctx = stream_context_create();
					$pem = 'e:\appbaba\statics\pem\10\apns-dis.pem';
					stream_context_set_option($ctx,"ssl","local_cert",$pem);
					$fp = stream_socket_client("ssl://gateway.push.apple.com:2195", $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
					if (!$fp) {/*  echo "Failed to connect $err $errstrn"; */
						$arr['im']['state'] = 'error';
					}else{
						$payload = json_encode($body);

						$msg = chr(0) . pack("n",32) . pack("H*", str_replace(' ', '', $userinfo[0]['token'])) . pack("n",strlen($payload)) . $payload;
						$result = fwrite($fp, $msg, strlen($msg));
						if (!$result){
							//echo "sending error : dev:".$userinfo[0]['token'];
							//$arr['im']['state'] = 'error';
							$this->error('推送失败');
						}
					}
		}elseif($systype==''){
				$sms = $this->sendsms($phone,$data['content']);
				if($sms!==1){
						//$arr['im']['state'] = 'error';
						$this->error('推送失败'.$phone);
				}

		}
		//if($arr['im']['state'] == 'success'){
		$lastInsId = $message->add($data);
		//}
		$this->success('发送成功');


    	//$data=$this->_post();

    }

	public function imp()
    {
    	$pid =$_REQUEST['pid'];
    	$cid =$_REQUEST['cid'];
    	$this->assign('cid',$cid);
    	$this->assign('pid',$pid);
    	$teacher_id =$_SESSION['teacher_id'];
		$this->assign('teacher_id',$teacher_id);


    	$user_id =getinfo($_SESSION['teacher_id'],'teacher','user_id');
    	$tuser_id =getinfo($pid,'parent','user_id');
    	$message=M('message');
    	$meslist =$message->where('send_id ='.$user_id .' and receive_id='.$tuser_id)->order('time desc')->select();
    	$this->assign('user_id',$user_id);
    	$this->assign('tuser_id',$tuser_id);
    	$this->assign('tid',$tid);

    	$this->assign('meslist',$meslist);
    	$this->display();
    }

    public function im()
    {
    	$tid =$_REQUEST['tid'];
    	$teacher_id =$_SESSION['teacher_id'];

    	$this->assign('tid',$tid);
    	$this->assign('teacher_id',$teacher_id);

    	$user_id =getinfo($_SESSION['teacher_id'],'teacher','user_id');
    	$tuser_id =getinfo($tid,'teacher','user_id');
    	$message=M('message');
    	$meslist =$message->where('send_id ='.$user_id .' and receive_id='.$tuser_id)->order('time desc')->select();
    	//echo $message->getlastsql();
    	$this->assign('user_id',$user_id);
    	$this->assign('tuser_id',$tuser_id);
    	$this->assign('tid',$tid);

    	$this->assign('meslist',$meslist);
    	$this->display();
    }

    public function im_info()
    {
        $tid=$_REQUEST['tid'];
        $this->assign('tid',$tid);
        $mteacher=M('teacher');
        $map['id']=$tid;
        $teacherinfo =$mteacher->find($tid);
        $this->assign('teacherinfo',$teacherinfo);
        $this->display();
    }
    public function imp_info()
    {
        $pid=$_REQUEST['pid'];
        $cid=$_REQUEST['cid'];
        $this->assign('pid',$pid);
        $this->assign('cid',$cid);

        $mparent=M('parent');
        $map['id']=$tid;
        $parentinfo =$mparent->find($pid);
        $this->assign('parentinfo',$parentinfo);
        $this->display();
    }


//update by ken 10.12

	private function getclassbyschool(){
		$school_id = $_SESSION['school_id'];
		$m = M('class');
		$data['school_id'] = $school_id;
		$list = $m->where($data)->select();
		return $list;
	}


	public function showclassstu(){
		$class_id = $_POST['class_id'];
		$stu = M('student');
		$data['class_id'] = $class_id;
		$list = $stu->where($data)->select();
//		echo $stu->getlastsql();
		$str.= '';
		foreach($list as $l){
			$str.='<div style="float:left;padding:5px;word-wrap: break-word;word-break: break-all;"><input type="checkbox" name="stu_id[]" value="'.$l[id].'" />'.$l['XM'].'</div>';
		}
		echo  $str;
	}
	//pro_del
	function pro_del()
    {

        $id = $this->_loadids();
        $map1['id'] =array('in',$id);
        $mschool_proclamation=M('class_proclamation');
        $mschool_proclamation->where($map1)->delete();
        add_log($_SESSION['teacher_id'],'删除 ID:'.$id.'班级公告',2);
        $this->success('删除成功');

    }

    function pro_sdel()
    {

        $id = $this->_loadids();
        $map1['id'] =array('in',$id);
        $mschool_proclamation=M('school_proclamation');
        $mschool_proclamation->where($map1)->delete();
        add_log($_SESSION['teacher_id'],'删除 ID:'.$id.'班级公告',2);
        $this->success('删除成功');

    }



}